//
//  ImageCellData.m
//  18Birdies
//
//  Created by 冯琦帆 on 15/12/2.
//  Copyright © 2015年 Lc. All rights reserved.
//

#import "ImageCell.h"
#import "ImageCellData.h"
#import "LcFoundation.h"

@implementation ImageCellData

+ (instancetype)cellDataWithImage:(UIImage*)image andImageHeight:(CGFloat)height {
  LC_CHECK_NOT_NULL(image);
  ImageCellData* cellData = [[self alloc] init];
  cellData->_image = image;
  cellData.cellHeight = height;
  cellData.imageContentMode = UIViewContentModeScaleAspectFill;
  cellData.backgroudColor = [UIColor whiteColor];
  cellData.margin = 0.0;
  return cellData;
}

- (Class)cellClazz {
  return [ImageCell class];
}

- (NSString*)nibName {
  return @"ImageCell";
}

- (void)refreshCell:(ImageCell*)cell {
  [super refreshCell:cell];
  if (self.placeholderImage) {
    cell.backgroundImageView.image = self.placeholderImage;
  } else {
    cell.backgroundImageView.image = nil;
  }
  cell.backgroundImageView.image = self.image;
  cell.backgroundImageView.clipsToBounds = self.clipsToBounds;
  for (UIView* view in cell.backgroundImageView.subviews) {
    view.contentMode = self.imageContentMode;
  }
  cell.backgroundImageView.contentMode = self.imageContentMode;
  cell.backgroundColor = self.backgroudColor;
  cell.leftMargin.constant = self.margin;
  cell.rightMargin.constant = self.margin;
}

@end
